home *** CD-ROM | disk | FTP | other *** search
/ TeX 1995 July / TeX CD-ROM July 1995 (Disc 1)(Walnut Creek)(1995).ISO / graphics / gnuplot / contrib / green / greenps.macros < prev   
Internet Message Format  |  1992-11-05  |  16KB

  1. From oliveria%rootbeer.engin.umich.edu@srvr2.engin.umich.edu Mon Aug 17 13:18:10 1992
  2. Return-Path: <oliveria%rootbeer.engin.umich.edu@srvr2.engin.umich.edu>
  3. Received: from srvr2.engin.umich.edu by ra-next.arc.nasa.gov (NeXT-1.0 (From Sendmail 5.52)/NeXT-1.0)
  4.     id AA05449; Mon, 17 Aug 92 13:18:05 PDT
  5. Received: from rootbeer.engin.umich.edu by srvr2.engin.umich.edu (5.64/1.35)
  6.     id AA12699; Mon, 17 Aug 92 16:31:22 -0400
  7. Received: by rootbeer.engin.umich.edu (5.64/1.35)
  8.     id 5a9eb2e98.00251f6; Mon, 17 Aug 92 16:31:19 -0400
  9. Date: Mon, 17 Aug 92 16:31:19 -0400
  10. From: Roque Donizete de Oliveira <oliveria@engin.umich.edu>
  11. Message-Id: <5a9eb2e98.00251f6@rootbeer.engin.umich.edu>
  12. To: woo@ra-next.arc.nasa.gov
  13. Subject: Re:  greek symbols in gnuplot
  14. Status: R
  15.  
  16. I include Martin Green's postscript macros for
  17. font mixing at the end of this message. It might
  18. be a good a idea to try to contact him to see if
  19. there is a newer version (perhaps easier to use and
  20. more similar to LaTeX usage, like using _ and ^).
  21.  
  22. I'm not sure what is best way of solving this problem.
  23. One could define in the gnudict prologue things like
  24.  
  25.  /\alpha {/Symbol findfont 200 scalefont setfont (a) } def
  26.  
  27. so that one could say (in gnuplot) 
  28.  
  29.                       set x label  "\alpha"
  30.  
  31. and get in the postscript file something like 
  32.  
  33.                       100 100 moveto \alpha show
  34.  
  35.  
  36. Now the Symbol font is active and something has to
  37. be done to get back the default font and font size
  38. (one could put everything with a gsave/grestore pair
  39. but then one would have to account for the stringwidth
  40. if doing mixed font stuff). And this doesn't even
  41. include subscripting/superscripting yet.
  42.  
  43. I like the ability to just use \alpha to get that
  44. symbol. Thus it would be nice to somehow modify
  45. Martin Green's macros to use shortnames like \perp
  46. instead of \136.
  47.  
  48. It should be relatively straightforward to use Martin Green's
  49. macros as is, if a new set of gnuplot commands, valid only
  50. for the postscript driver, were created. Like
  51.  
  52. set psxlabel "[string1 sups [string2 string3 subs [{PS S} string4 {PS H}]] string5]"
  53.  
  54. Perhaps a modifier could be added to the labelling commands.
  55. Like
  56.           set xlabel {"<label>"} {<xoff>}{,<yoff>} {ps}
  57.  
  58. in which case the "ps" would mean the label is to
  59. be passed AS IS to Martin Green's display operator. Thus
  60.           set xlabel "[{12 H} (M) subs [{8 S} (a)] (\(x\))]" ps
  61. would create the following postscript code:
  62.  
  63.    100 100 moveto % this varies, of course
  64.    [{12 H} (M) subs [{8 S} (a)] (\(x\))] display
  65.  
  66. and so we have the LaTeX equivalent of $M_{\alpha}(x)$. It
  67. isn't exactly the same for we would be using 12pt Helvetica
  68. to write the "M" and "(x)". I guess it is more like
  69.    M${}_{\alpha}$(x)
  70.  
  71. Anyway, here are the macros:
  72.  
  73.  
  74.  
  75. %
  76. % Procedures for string handling. 
  77. % From USENET posting in comp.lang.postscript by:
  78. % Martin Green                        UUCP     :  ..!torsqnt!ohrd!green
  79. % Ontario Hydro Research Division     Telephone:  (416)231-4111 Ext7060
  80. % 800 Kipling Ave
  81. % Toronto, Ontario, CANADA, M8Z5S4
  82. %
  83. % Copyright (C) 1990 Martin A. Green
  84. %
  85. % Last edited: Fri Nov  2 09:09:22 EST 1990
  86. %    
  87. % This program is free software; you can redistribute it and/or modify
  88. % it under the terms of the GNU General Public License as published by
  89. % the Free Software Foundation; either version 1, or (at your option)
  90. % any later version.
  91. %    
  92. % This program is distributed in the hope that it will be useful,
  93. % but WITHOUT ANY WARRANTY; without even the implied warranty of
  94. % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  95. % GNU General Public License for more details.
  96. %    
  97. % You should have received a copy of the GNU General Public License
  98. % along with this program; if not, write to the Free Software
  99. % Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  100. %
  101. % ----------------------------------------------------------------------
  102. % Text manipulation functions including super- and sub-scripts,
  103. % multiple fonts and sizes, centering and right alignment, and
  104. % full justification.
  105. %
  106. % Example:
  107. %
  108. %   [string1 sups [string2 string3 subs string4] {font2} string5] display
  109. %
  110. % should print string1 with the current font, then go into superscript 
  111. % mode for string2 and string3, then print string4 as a subscript to 
  112. % string3, then return to the original font, followed by a change to font2,
  113. % and finally print string5.  The positioning and angle of the printed 
  114. % text are determined by the /textalign and /textangle variables.
  115. %
  116. % Font selection: To select Times-Roman 12 point font use: 12 R
  117. %
  118. % Additional notes & changes (C. Towne):
  119. %
  120. % 1.  In the above example, to change fonts in the middle of a display,
  121. %     but keep the same point size, do something like:
  122. %
  123. %        [string1 sups [string2 string3 subs [string4]] {PS S} string5] display
  124. %
  125. % 2.  To change fonts in the middle of a display, and change the point size,
  126. %     do:
  127. %
  128. %        [string1 sups [string2 string3 subs [string4]] {nn S} string5] display
  129. %
  130. %     where nn is the desired point size.
  131. %
  132. % 3.  To change fonts for a subscript (or superscript) from, say, Helvetica
  133. %     to Symbol, do:
  134. %     
  135. %        [string1 sups [string2 string3 subs [{PS S}string4{PS H}]] string5]
  136. %        display
  137. %
  138. % 4.  gsave & grestore added to displaywidth procedure.  Without it
  139. %     entire string would be displayed in last font used.
  140. %
  141. % 5.  The /textangle option apparently is missing.
  142. %
  143. % 6.  Stuff for centered symbols has been removed.
  144. %
  145. % 7.  Procedures displaybbox and displaybbox2 (similar to displaywidth and
  146. %     displaywidth2) added.
  147. %
  148. % 8.  Font names changed to same as those in troff, and added CB, CO, CD.
  149. %
  150. % 9.  Coding style changes made.
  151. %
  152.  
  153. % Font definitions
  154. /H  {dup /PS exch def
  155.      /Helvetica findfont exch scalefont setfont} def
  156. /HB {dup /PS exch def
  157.      /Helvetica-Bold findfont exch scalefont setfont} def
  158. /HO {dup /PS exch def 
  159.      /Helvetica-Oblique findfont exch scalefont setfont} def
  160. /HD {dup /PS exch def
  161.      /Helvetica-BoldOblique findfont exch scalefont setfont} def
  162. /R  {dup /PS exch def 
  163.      /Times-Roman findfont exch scalefont setfont} def
  164. /B  {dup /PS exch def
  165.      /Times-Bold findfont exch scalefont setfont} def
  166. /I  {dup /PS exch def
  167.      /Times-Italic findfont exch scalefont setfont} def
  168. /BI {dup /PS exch def
  169.      /Times-BoldItalic findfont exch scalefont setfont} def
  170. /C  {dup /PS exch def 
  171.      /Courier findfont exch scalefont setfont} def
  172. /CB {dup /PS exch def 
  173.      /Courier-Bold findfont exch scalefont setfont} def
  174. /CO {dup /PS exch def 
  175.      /Courier-Oblique findfont exch scalefont setfont} def
  176. /CD {dup /PS exch def 
  177.      /Courier-BoldOblique findfont exch scalefont setfont} def
  178. /S  {dup /PS exch def 
  179.      /Symbol findfont exch scalefont setfont} def
  180.  
  181. /STRING (a) type cvlit def
  182. /ARRAY  [0] type cvlit def
  183. /LEFT  -1 def
  184. /CENTRE 0 def
  185. /RIGHT  1 def
  186. /CENTER CENTRE def
  187.  
  188. /exactwidth 0 def    % line added (CET)
  189. /textalign LEFT def    % line added (CET)
  190. /fontstore 5 array def
  191. /vshift    5 array def
  192. /fontlevel 0 def
  193.  
  194. /pushfont {
  195.    fontstore exch [ exch PS ] fontlevel exch put
  196.    /fontlevel fontlevel 1 add def
  197. } def
  198.  
  199. /popfont {
  200.    0 vshift fontlevel get neg rmoveto
  201.    vshift fontlevel 0 put
  202.    /fontlevel fontlevel 1 sub def
  203.    fontstore fontlevel get aload pop /PS exch def setfont
  204. } def
  205.  
  206. /sups {        % adjust position and reduce font size for superscripts
  207.    {currentfont dup pushfont .8 scalefont setfont
  208.    vshift fontlevel PS .4 mul put
  209.    0 PS .4 mul rmoveto
  210.    /PS PS .8 mul def}
  211. } def
  212.  
  213. /subs {        % adjust position and reduce font size for subscripts
  214.    {currentfont dup pushfont .8 scalefont setfont
  215.    vshift fontlevel PS -.3 mul put
  216.    0 PS -.3 mul rmoveto
  217.    /PS PS .8 mul def}
  218. } def
  219.  
  220. /isstring {    % return true if argument is a string
  221.    type cvlit STRING eq
  222. } def
  223.  
  224. /isarray {    % return true if argument is an array
  225.    type cvlit ARRAY eq 
  226. } def
  227.  
  228. %
  229. % compute width of complex text array
  230. %
  231.  
  232. /displaywidth {
  233.    gsave
  234.    /textwidth 0 def
  235.    /textheight PS def
  236.    /fontlevel 0 def
  237.    /displevel 0 def
  238.    {        % step through array elements
  239.       dup isstring {
  240.          stringwidth pop /textwidth exch textwidth add def
  241.          fontlevel displevel sub 1 eq {popfont} if
  242.       } {
  243.       dup xcheck {
  244.          exec
  245.       } {
  246.       dup isarray {
  247.          displaywidth2
  248.          fontlevel displevel sub 1 eq {popfont} if
  249.       } {    % error handler
  250.          pop
  251.       } ifelse } ifelse } ifelse
  252.    } forall
  253.    grestore
  254. } def
  255.  
  256. /displaywidth2 {
  257.    /displevel displevel 1 add def
  258.    {        % step through array elements
  259.          dup isstring {
  260.          stringwidth pop /textwidth exch textwidth add def
  261.          fontlevel displevel sub 1 eq {popfont} if
  262.       } {
  263.       dup xcheck {
  264.          exec
  265.       } {
  266.       dup isarray {
  267.          displaywidth2
  268.          fontlevel displevel sub 1 eq {popfont} if
  269.       } {    % error handler
  270.          pop
  271.       } ifelse } ifelse } ifelse
  272.    } forall
  273.    /displevel displevel 1 sub def
  274. } def
  275.  
  276. %
  277. % Compute bounding box of complex text array.
  278. %    llx = llx of first character
  279. %    urx = current x + width of complete complex text array - right side
  280. %          bearing of last character in last string.  Right side bearing =
  281. %          current x + character width - urx of character bbox.
  282. %    lly = min of lly's from each character
  283. %    ury = max of ury's from each character
  284. % Note that urx is recomputed for each string in complex text array.
  285. %
  286.  
  287. /displaybbox {
  288.    gsave
  289.  
  290.    % compute dimensions if required
  291.    currentpoint 3 -1 roll
  292.    /textwidth 0 def
  293.    exactwidth 0 ne textalign LEFT ne or
  294.       {dup displaywidth} if
  295.  
  296.    % adjust starting position and angle
  297.    3 1 roll moveto
  298.    textalign LEFT ne {textalign RIGHT eq { textwidth neg 0 rmoveto }
  299.                         {textwidth 2 div neg 0 rmoveto } ifelse } if
  300.  
  301.    % initialize some stuff
  302.    /fontlevel 0 def
  303.    /displevel 0 def
  304.    /tempstr 1 string def    % 1-char string for getting lly and ury
  305.    /charn 1 string def
  306.    /urx -10000 def        % bbox limits
  307.    /lly  10000 def
  308.    /ury -10000 def
  309.    /firstdone false def        % flag for "1st. char done?"
  310.  
  311.    % get width of complete complex text array (textwidth)
  312.    dup displaywidth
  313.  
  314.    % save current point
  315.    currentpoint /ycp exch def /xcp exch def
  316.  
  317.    % loop to step through all array elements
  318.    {
  319.  
  320.       % array element is a string
  321.       dup isstring {
  322.  
  323.          % get llx from bbox of first char
  324.          firstdone not {
  325.             dup             %stk: string string
  326.             gsave
  327.             0 1 getinterval        %stk: string char1
  328.             true charpath flattenpath
  329.             pathbbox pop pop pop    %stk: string llx
  330.             /llx exch def        %stk: string
  331.             /firstdone true def
  332.             grestore
  333.          } if
  334.  
  335.          % get urx from current x, width of complete array, and right side
  336.          % bearing of last character
  337.          dup                 %stk: string string
  338.          gsave
  339.          dup length 1 sub get        % define string containing last char
  340.          charn 0 3 -1 roll put        %stk: string
  341.          charn stringwidth pop        % get width of last char
  342.          /cwidth exch def
  343.          newpath            % get bbox of last char
  344.          xcp ycp moveto
  345.          charn true charpath flattenpath
  346.          pathbbox pop            %stk: string llx lly urx
  347.          cwidth xcp add exch sub    % define right side bearing of last char         
  348.          /rsb exch def pop pop         %stk: string
  349.          xcp textwidth add rsb sub    % get urx
  350.          /urx exch def
  351.          grestore
  352.  
  353.          % get lly and ury from bbox of each character
  354.          {                % loop over each character in string
  355.             gsave
  356.             tempstr 0 3 -1 roll        %stk: tempstr 0 char
  357.             put                % put character into tempstr
  358.             newpath            % get bbox of char
  359.             xcp ycp moveto
  360.             tempstr true charpath flattenpath
  361.             pathbbox            %stk: llx lly urx ury
  362.             ury amax1 /ury exch def    % get ury
  363.             exch            %stk: llx urx lly
  364.             lly amin1 /lly exch def    % get lly
  365.             pop pop            %stk:
  366.             grestore
  367.          } forall
  368.          fontlevel displevel sub 1 eq {popfont} if
  369.       } {
  370.  
  371.       % array element is executable
  372.       dup xcheck {
  373.          exec
  374.       } {
  375.  
  376.       % array element is an array
  377.       dup isarray {
  378.          displaybbox2
  379.          fontlevel displevel sub 1 eq {popfont} if
  380.  
  381.       % error
  382.       } {
  383.          pop
  384.       } ifelse } ifelse } ifelse
  385.    } forall
  386.    llx lly urx ury            %stk: llx lly urx ury
  387.    grestore
  388. } def
  389.  
  390. /displaybbox2 {
  391.    /displevel displevel 1 add def
  392.  
  393.    % loop to step through all array elements
  394.    {
  395.  
  396.       % array element is a string
  397.       dup isstring {
  398.  
  399.          % get llx from bbox of first char
  400.          firstdone not {
  401.             dup             %stk: string string
  402.             gsave
  403.             0 1 getinterval        %stk: string char1
  404.             true charpath flattenpath
  405.             pathbbox pop pop pop    %stk: string llx
  406.             /llx exch def        %stk: string
  407.             /firstdone true def
  408.             grestore
  409.          } if
  410.  
  411.          % get urx from current x, width of complete array, and right side
  412.          % bearing of last character
  413.          dup                 %stk: string string
  414.          gsave
  415.          dup length 1 sub get        % define string containing last char
  416.          charn 0 3 -1 roll put        %stk: string
  417.          charn stringwidth pop        % get width of last char
  418.          /cwidth exch def
  419.          newpath            % get bbox of last char
  420.          xcp ycp moveto
  421.          charn true charpath flattenpath
  422.          pathbbox pop            %stk: string llx lly urx
  423.          cwidth xcp add exch sub    % define right side bearing of last char         
  424.          /rsb exch def pop pop         %stk: string
  425.          xcp textwidth add rsb sub    % get urx
  426.          /urx exch def
  427.          grestore
  428.  
  429.          % get lly and ury from bbox of each character
  430.          {                % loop over each character in string
  431.             gsave
  432.             tempstr 0 3 -1 roll        %stk: tempstr 0 char
  433.             put                % put character into tempstr
  434.             newpath            % get bbox of char
  435.             xcp ycp moveto
  436.             tempstr true charpath flattenpath
  437.             pathbbox            %stk: llx lly urx ury
  438.             ury amax1 /ury exch def    % get ury
  439.             exch            %stk: llx urx lly
  440.             lly amin1 /lly exch def    % get lly
  441.             pop pop            %stk:
  442.             grestore
  443.          } forall
  444.          fontlevel displevel sub 1 eq {popfont} if
  445.       } {
  446.  
  447.       % array element is executable
  448.       dup xcheck {
  449.          exec
  450.       } {
  451.  
  452.       % array element is an array
  453.       dup isarray {
  454.          displaybbox2
  455.          fontlevel displevel sub 1 eq {popfont} if
  456.  
  457.       % error
  458.       } {
  459.          pop
  460.       } ifelse } ifelse } ifelse
  461.    } forall
  462.    /displevel displevel 1 sub def
  463. } def
  464.  
  465. %
  466. % display complex text array
  467. %
  468.  
  469. /display {
  470.    currentpoint 3 -1 roll
  471.    /textwidth 0 def
  472.    exactwidth 0 ne textalign LEFT ne or        % compute dimensions if required
  473.       {dup displaywidth} if
  474.    % adjust starting position and angle
  475.    3 1 roll moveto
  476.    textalign LEFT ne {textalign RIGHT eq { textwidth neg 0 rmoveto }
  477.                         {textwidth 2 div neg 0 rmoveto } ifelse } if
  478.    % print text
  479.    /fontlevel 0 def
  480.    /displevel 0 def
  481.    {        % step through array elements
  482.       dup isstring {
  483.          show
  484.          fontlevel displevel sub 1 eq {popfont} if
  485.       } {
  486.       dup xcheck {
  487.          exec
  488.       } {
  489.       dup isarray {
  490.          display2
  491.          fontlevel displevel sub 1 eq {popfont} if
  492.       } {    % error handler
  493.          pop
  494.       } ifelse } ifelse } ifelse
  495.    } forall
  496. } def
  497.  
  498. /display2 {
  499.    /displevel displevel 1 add def
  500.    {        % step through array elements
  501.       dup isstring {
  502.          show
  503.          fontlevel displevel sub 1 eq {popfont} if
  504.       } {
  505.       dup xcheck {
  506.          exec
  507.       } {
  508.       dup isarray {
  509.          display2
  510.          fontlevel displevel sub 1 eq {popfont} if
  511.       } {    % error handler
  512.          pop
  513.       } ifelse } ifelse } ifelse
  514.    } forall
  515.    /displevel displevel 1 sub def
  516. } def
  517.  
  518.